<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/27
  Time: 10:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-1.8.2.min.js"></script>
    <script src="../../js/fileupload.js"></script>
    <link rel="stylesheet" href="../../css/img.css">
    <link rel="stylesheet" href="../../bootstrap-4.6.0-dist/css/bootstrap.min.css">

</head>
<body>

<form>
    ID:<input type="text" name="hid" value="${param.hid}"><br>
    小区名称：<input type="text" name="hname"><br>
    单元楼：<input type="text" name="building"><br>
    门牌号：<input type="text" name="number"><br><br>
    实景图：
    <div class="photoUpLoad" >
    <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
    <img src="" alt="" class="photoEcho">
</div><br><br>
    状态：<select name="statu">
    <option value="">请选择状态</option>
    <option value="0">待租</option>
    <option value="1">出租</option>
</select><br>
    挂牌时间：<input type="text" name="gtime"><br>
    出租时间：<input type="text" name="ctime"><br>
    房屋类型：
    <select name="tid">
        <option value="">请选择类型</option>
    </select>
</form>
<input type="button" value="修改" onclick="upda()"  class="btn btn-warning">

</body>
</html>
<script>

    $.ajax({
        url:"listt.do",
        type:"post",
        dataType:"json",
        success:function (data) {
            for (let i = 0; i <data.length ; i++) {
                $("[name='tid']").append('<option value="'+data[i].tid+'">'+data[i].tname+'</option>')
            }
        }
    })

    $.ajax({
        url:"hui.do",
        data: {"hid":${param.hid}},
        type:"post",
        dataType:"json",
        success:function (data) {
            console.log(data)
            $("[name='hname']").val(data.hname)
            $("[name='building']").val(data.building)
            $("[name='number']").val(data.number)
            $("[name='gtime']").val(data.gtime)
            $("[name='ctime']").val(data.ctime)
            $("[name='statu']").val(data.statu)
            $(".photoEcho").prop("src",data.imgs)
            $("[name='tid']").val(data.tid)
        }
    })

    function upda() {
        var formData = new FormData($("form")[0]);
        $.ajax({
            url: "upda.do",
            data:formData,
            type: "post",
            dataType: "json",
            success:function (data) {
                if (data>0){
                    alert("修改成功")
                    location="list.do"
                }else{
                    alert("修改失败")
                }
            },processData:false,contentType:false
        })
    }


</script>
















